package com.design3.graduatethesissys.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.design3.graduatethesissys.common.utils.GetUserName;
import com.design3.graduatethesissys.domain.Student;
import com.design3.graduatethesissys.mapper.MessageMapper;
import com.design3.graduatethesissys.mapper.StudentMapper;
import com.design3.graduatethesissys.service.StudentService;

/** 
* @author 作者 罗穆健: 
* @version 创建时间：2020年1月10日 下午10:45:56 
* 类说明 
*/
@Service
public class StudentServiceImpl implements StudentService{
	
	@Autowired
	StudentMapper studentMapper;
	@Autowired
	MessageMapper messageMapper;

	@Override
	public List<Map<String, Object>> getTeacher() {
		List<Map<String, Object>> teacherList = new ArrayList<>();
		String id = GetUserName.getUserName();
		Map<String, Object> map1 = studentMapper.getTeacher(id);
		if(map1!=null) {
			Map<String, Object> map2 = messageMapper.getCountMessage(id,(String)map1.get("teh_id")); 
			map2.put("count", map2.get("count(*)"));
			teacherList.add(map1);
			teacherList.add(map2);
		}
		return teacherList;
	}

	@Override
	public String updateStudent(Student student) {
		// TODO Auto-generated method stub
		try {
			studentMapper.updateStudent(student);
			return "修改成功";
		} catch (Exception e) {
			return "修改失败";
		}
		
	}
	
	@Override
	public Student getStudent() {
		// TODO Auto-generated method stub
		return studentMapper.getStudent(GetUserName.getUserName());
	}

}
 